package com.primus.server.service.store.impl;

import com.primus.server.entity.store.Store;
import com.primus.server.repository.StoreRepository;
import com.primus.server.service.BaseServiceImpl;
import com.primus.server.service.store.StoreService;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class StoreServiceImpl extends BaseServiceImpl<Store> implements StoreService {

    private final StoreRepository storeRepository;

    public StoreServiceImpl(StoreRepository storeRepository) {
        this.storeRepository = storeRepository;
    }

    @Override
    protected JpaRepository<Store, Long> getRepository() {
        return this.storeRepository;
    }

    @Override
    public Store findByUserId(Long userId) {
        Optional<Store> optional = this.storeRepository.findByOwnersContains(userId);
        return optional.orElse(null);
    }
}
